home *** CD-ROM | disk | FTP | other *** search
- /*
- WASTE Demo Project:
- About Boxes
-
- Copyright © 1993-1995 Marco Piovanelli
- All Rights Reserved
-
- C port by John C. Daub
- */
-
-
- #ifndef __WEDEMOAPP__
- #include "WEDemoIntf.h"
- #endif
-
- // some local stuff
-
- #define kItemTextPane 3
-
- static UserItemUPP sBoxPainter;
-
- static pascal void DrawUserItem( DialogRef, short );
-
-
- OSErr WETextBox( short textResID, const Rect *bounds, short alignment )
- {
- WEReference we = NULL;
- LongRect longBounds;
- Handle hText = NULL;
- Handle hStyles = NULL;
- SignedByte saveTextState, saveStylesState;
- OSErr err;
-
- // create a new WE instance
-
- WERectToLongRect( bounds, &longBounds );
- err = WENew( &longBounds, &longBounds, 0, &we );
- if ( err != noErr )
- goto cleanup;
-
- // set the alignment style
-
- WESetAlignment( alignment, we );
-
- // load the styl resource and make it unpurgeable
-
- hStyles = GetResource( kTypeStyles, textResID );
- err = ResError();
- if ( err != noErr )
- goto cleanup;
- saveStylesState = HGetState( hStyles );
- HNoPurge( hStyles );
-
- // load the text resource and lock it
-
- hText = GetResource( kTypeText, textResID );
- err = ResError();
- if ( err != noErr )
- goto cleanup;
- saveTextState = HGetState( hText );
- HLockHi( hText );
-
- // insert the text
-
- err = WEInsert( *hText, GetHandleSize( hText ), (StScrpHandle)hStyles, NULL, we );
- if ( err != noErr )
- goto cleanup;
-
- // clear the result code
-
- err = noErr;
-
- // cleanup
-
- cleanup:
-
- if ( hText != NULL )
- HSetState( hText, saveTextState );
-
- if ( hStyles != NULL )
- HSetState( hStyles, saveStylesState );
-
- WEDispose( we );
-
- // return the result code
-
- return err;
- }
-
- pascal void DrawUserItem( DialogRef dialog, short item )
- {
- Rect r;
-
- // draw the text, centered, in the item rect
-
- GetDialogItemRect( dialog, item, &r );
-
- if ( WETextBox( GetWRefCon(GetDialogWindow(dialog)), &r, weCenter) != noErr )
- ; // insert error handling here
-
- return;
- }
-
-
- void DoAboutBox( short dialogID )
- {
- DialogRef aboutBox;
- short itemHit;
-
- // get the about box
-
- aboutBox = GetNewDialog( dialogID, NULL, (WindowRef)-1L );
- if ( aboutBox == NULL )
- return;
-
- // install a user item drawing procedure for the text pane
-
- if ( sBoxPainter == NULL )
- sBoxPainter = NewUserItemProc( DrawUserItem );
- SetDialogItemProc( aboutBox, kItemTextPane, sBoxPainter );
-
- // store ID of TEXT/styl pair (= ID of dialog template) in dialog refCon
-
- SetWRefCon( GetDialogWindow(aboutBox), dialogID );
-
- // put up the dialog
-
- SetCursor( &qd.arrow );
-
- ShowWindow( GetDialogWindow(aboutBox) );
- SetGrafPortOfDialog(aboutBox);
-
- // wait for a click
-
- ModalDialog( GetMyStandardDialogFilter(), &itemHit );
-
- // bring down the dialog
-
- DisposeDialog( aboutBox );
-
- return;
- }